 
var xmlhttp = null;
var one = -1;

function load(){
	document.getElementById("user").addEventListener("keyup",isExits,true);
	document.getElementById("pass").addEventListener("click",isLogin,true);
}

//�¼��� ��ť�¼�
function isLogin(){
	  
	xmlhttp = getRequest();
	var val = document.getElementById("user").value;
	var pwd = document.getElementById("pass").value;
	 
	//ת��
	zhuan(val);
	zhuan(pwd);
	if(val==""){
		document.getElementById("zh").innerHTML="<font color='red'>�˺Ų���Ϊ��</font>"; 
		return;
	}
	if(pwd==""){
		document.getElementById("mm").innerHTML="<font color='red'>���벻��Ϊ��</font>";
		return;
	}
	 
	var url = "UserServlet?action=isLogin&name="+val+"&pwd="+pwd;
	xmlhttp.open("get",url);
	xmlhttp.onreadystatechange=callLogin;//�ص�
	xmlhttp.send(null);
	
}

//�¼���
function isExits(){ 
		xmlhttp = getRequest();
		var user = document.getElementById("user").value;
		user = encodeURI(user);
		user = encodeURI(user);
		
		//�����Ϊ�ղ����е���
		if(user==""){
			document.getElementById("tip").innerHTML="";
			return;
		}
		var url = "UserServlet?action=isName&name="+user;
		xmlhttp.open("get",url);
		xmlhttp.onreadystatechange=callUser;//�ص�
		xmlhttp.send(null);
	 
}
//�ص����� ��¼��ť
function callLogin(){
	if(xmlhttp.readyState ==4 && xmlhttp.status==200){ 
		
		var json = xmlhttp.responseText;
		if(json=="no"){
			alert("��¼ʧ��");
		}else if(json=="yes"){
			alert("��¼�ɹ�");
			window.open("Index.html");
		}
	}
}

function getRequest(){
	/*
	var httpRequest = new XMLHttpRequest();
	return httpRequest;
	*/
	var xmlhttp;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return xmlhttp ;
}

//ת��
function zhuan(obj){
	obj = encodeURI(obj);
	obj = encodeURI(obj);
	
	 
}